#include "GameAppImpl.h"
#include "d3ddefs.h"

GameAppImpl::GameAppImpl()
	:UpdateFuncPtr(NULL)
	,RenderFuncPtr(NULL)
{

}

GameAppImpl::~GameAppImpl()
{

}

void GameAppImpl::InitScene(void)
{
	D3DXMatrixPerspectiveFovLH(&m_matProjection,m_fFieldOfView,m_fAspectRatio,m_fNearPlane,m_fFarPlane);
	m_pDirect3DDevice->SetTransform(D3DTS_PROJECTION,&m_matProjection);


	m_pDirect3DDevice->SetRenderState(D3DRS_AMBIENT,RGB(255,255,255));
	m_pDirect3DDevice->SetRenderState(D3DRS_LIGHTING,false);
	m_pDirect3DDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
	m_pDirect3DDevice->SetRenderState(D3DRS_ZENABLE,D3DZB_TRUE);

	for(unsigned i = 0;i < 8;++i)
	{
		m_pDirect3DDevice->SetSamplerState(i,D3DSAMP_MINFILTER,D3DTEXF_LINEAR);
		m_pDirect3DDevice->SetSamplerState(i,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR);
		m_pDirect3DDevice->SetSamplerState(i,D3DSAMP_MIPFILTER,D3DTEXF_ANISOTROPIC);
		m_pDirect3DDevice->SetSamplerState(i,D3DSAMP_MAXANISOTROPY,m_dwAnisotropy);
	}

	m_pDirect3DDevice->SetFVF(D3DFVF_CUSTOMVERTEX);

	


}

void GameAppImpl::DoFrame(float timeDelta)
{
	if( UpdateFuncPtr != NULL && RenderFuncPtr != NULL )
	{
		UpdateFuncPtr(timeDelta);
		RenderFuncPtr();
	}
}